'''
a=float(input("请输入斜�?1的长度："))
b=float(input("请输入斜�?1的长度："))
c=float(input("请输入斜�?1的长度："))
d=a+b+c
print("三角形的周长为：",d)
'''
'''
a=int(input("请输入一个数:"))
if a>0:
    print("a是一个正�?")
elif a<0:
    print("a是一个负�?")
else:
    print("a=0")
'''
'''
arr = []
evenStr=""
oddStr=""
message=input("请输入任意字符串�?")
for string in message:
    arr.append(string)
for eStr in (arr[::2]):
    evenStr =evenStr+eStr
for oStr in (arr[1::2]):
    oddStr = oddStr+oStr
print (evenStr+oddStr)    
'''
'''
arr=[]
length = int (input("请输入数字的总个数（必须是奇数）�?"))
i=0
while i<length:
    num = int (input("输入�?%d个数字："%(i+1)))
    arr.append(num)
    i+=1
arr.sort()
index=int(length/2)
print(arr[index])
'''
'''
dic={}
i=0
while i<3:
    number =input("输入学号:")
    name = input("输入姓名:")
    dic.__setitem__(number,name)
    i+=1
print("排序�?:%s"%dic)
def dict2list(dic:dict):
    keys=dic.keys()
    vals=dic.values()
    lst=[(key,val) for key,val in zip (keys,vals)]
    return lst
new = sorted(dict2list(dic),key=lambda x:x[0],reverse=False)
print("排序后：%s"%new)
'''
'''
import math
def isPrimeNumber(m):
    k = int(math.sqrt(m))
    for i in range(2, k + 1):
        if m % i == 0:
            return False
    return True
def getResult(x, y):
    for i in range(x + 1, y):
        if isPrimeNumber(i):
            print(i)

getResult(100, 200)
'''


'''
def isLeapYear(year):
    if year%400 == 0 or (year%4==0 and year%100!= 0):
        return 29
    else:
        return 28
def whichDay(year, month, day):
    if month < 1 or month > 12 or day > 31 or day < 1:
        return 0
    months=[31,isLeapYear(year),31,30,31,30,31,31,30,31,30,31]
    if day > months[month - 1]:
        return 0
    num = 0
    for i in range(0,month-1):
        num += months[i]
    return num + day
print(whichDay(2024,9,26))
'''

'''
fh = open("C:\\Users\\26356\\Desktop\\python\\静夜�?.txt", encoding='utf-8')
# 方式1 一次性读�?
content = fh.read()
print(content)
fh.close()
# 非二进制读取
fh = open("C:\\Users\\26356\\Desktop\\python\\静夜�?.txt", encoding='utf-8')
flag = True
while flag:
    content = fh.readline()
    if content != "":
        print(content)
    else:
        flag = False
fh.close()
# 按行
fh = open("C:\\Users\\26356\\Desktop\\python\\静夜�?.txt", encoding='utf-8')
content = fh.readlines()
print(content)
fh.close()
'''

'''
content ="登鹳雀楼\n作�?:王之涣\n白日依山尽\n黄河入海流\n欲穷千里目\n更上一层楼"
fh=open("C:\\Users\\26356\\Desktop\\python\\登鹳雀�?.txt", "a",encoding='utf-8')
fh.write(content)
fh.close()
#方式2 按行写入
content ="登鹳雀楼\n作�?:王之涣\n白日依山尽\n黄河入海流\n欲穷千里目\n更上一层楼"
fh=open("C:\\Users\\26356\\Desktop\\python\\登鹳雀�?.txt", "a",encoding='utf-8')
fh.writelines(content)
fh.close()
'''

'''
import  numpy as np
a=np.arange(25)
a=a.reshape((5,5))
b=np.array([10,62,1,14,2,56,79,2,1,45,4,92,5,55,63,43,35,6,53,24,56,3,56,44,78])
b=b.reshape((5,5))
print (a+b)
print(a-b)
print(a*b)
print(a/b)
'''

'''
class Bicycle(object):
    def __init__(self,color): 
        self.color=color
    def ride(self):
        print("自行车在骑行")
    def toot(self):
        print("自行车在鸣笛")
racingCycle=Bicycle("红色")
racingCycle.ride()
racingCycle.toot()
print("自行车颜色：",racingCycle.color)        
'''
'''
class Bicycle(object):
    def __init__(self,color):
        self.__color=color
racingCycle=Bicycle("红色")
print("自行车颜色：",racingCycle.__color)        
'''

'''
class Bicycle(object):
    def __init__(self, color):  
        self.__color = color  

    def get_color(self):
        return self.__color

    def set_color(self, color):
        self.__color = color

racingCycle = Bicycle("红色")
print("自行车颜�?:", racingCycle.get_color())
racingCycle.set_color("蓝色")  
print("自行车颜�?:", racingCycle.get_color())
'''
'''
class Stu():
    def __init__(self,name,age,score):
        self.__name=name
        self.__age=age
        self.__score=score
    def getName(self):
        return self.__name
    def getAge(self):
        return self.__age
    def getScore(self):
        return self.__score

    def setName(self,name):
        self.__name=name
    def setAge(self,age):
        self.__age=age
    def setScore(self,score):
        if score>=0 and score<=100:
            self.__score=score
        else:
            print("输入成绩超出范围")

xiaoMing=Stu("小明","19",60)
xiaoMing.setScore(90)
print(xiaoMing.getScore())
'''
'''
class Animal(object):
    def __init__(self,color="白色"):
        self.color=color
    def shout(self):
        print("�?")
class Cow(Animal):
    pass
mycow=Cow("黑白花牛")
print(mycow.color)
mycow.shout()
'''
'''
class Animal(object):
    def __init__(self,color="白色"):
        self.color=color
    def shout(self):
        print("�?")
class Cat(Animal):
    def shout(self):
        print("�?")
class Dog(Animal):
    def shout(self):
        print("�?")
def func(temp):
    temp.shout()
mycat=Cat()
mydog=Dog()
func(mycat)
func(mydog)
'''

'''
#7-10
import  numpy as np
a=np.arange(25)
a=a.reshape((5,5))
b=np.array([10,62,1,14,2,56,79,2,1,45,4,92,5,55,63,43,35,6,53,24,56,3,56,44,78])
b=b.reshape((5,5))
print (a+b)
print(a-b)
print(a*b)
print(a/b)
'''
#第一次是上一次的数组
'''
#7-10
import numpy as np
import pandas as pd
df1 = pd.DataFrame([[1,2,3,4],[4,5,6,7],[9,10,11,12],[13,14,45,16]],index=None,columns=['A','B','C','D'])
print(df1)
'''
'''
#7-11
import numpy as np
import pandas as pd
dic={'name':['小明','小红','杜鹃','李柱'],
    'age':[17,20,21,19],
    'gender':['�?','�?','�?','�?']}
df2=pd.DataFrame(dic,index=None,columns=['name','age','gender'])
print(df2)
elements1=df2['name']
print('element1的类�?:',type(elements1))
print(elements1)
elements2=df2.age
print('element2的类�?:',type(elements2))
print(elements2)
    'age':[17,20,21,19],
    'gender':['�?','�?','�?','�?']}
df2=pd.DataFrame(dic,index=None,columns=['name','age','gender'])
print(df2)

'''
'''
#7-12
import numpy as np
import pandas as pd
df3=pd.DataFrame(np.random.randn(4,3),index=None,columns=list('ABC'))
print(df3)
df3['D']=[11.0,22.0,33.0,44.0]
print(df3)
'''
'''
#7-13
import pandas as pd
dataf=pd.read_excel(r'C:\\Users\\26356\\Desktop\\python\\证券交易.xlsx',converters={u'代码':str})
print(dataf)
dataf1=dataf.loc[:,['代码','名称']]
print(dataf1)
dataf1.to_excel(r'C:\\Users\\26356\\Desktop\\python\\证券交易_代码名称.xlsx')

'''

import tushare as ts
token='c36e7499a4dfecd2f5ea0699669560e0fc003224b75cd80aaacda222'
ts.set_token(token)
pro=ts.pro_api()
df=pro.query('daily',ts_code='600928.SH',start_date='20210101',end_date='20241001')
print(df)
df.to_csv('./600928SH.csv')


from pyalgotrade.feed import csvfeed
import pandas as pd

def read_write_CSV(from_file, to_file):
    feed = csvfeed.Feed("trade_date", "%Y%m%d")
    feed.addValuesFromCSV(from_file)

    df = pd.DataFrame(columns=['Date Time', 'Open', 'High', 'Low', 'Close', 'Volume', 'Adj Close'])
    with open(to_file, 'w') as file:
        file.write("Date Time,Open,High,Low,Close,Volume,Adj Close\n")
        for dateTime, value in feed:
            strdatetime = dateTime.strftime("%Y-%m-%d %H:%M:%S")
            file.write("%s,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f\n" % (
                strdatetime,
                float(value['open']),
                float(value['high']),
                float(value['low']),
                float(value['close']),
                float(value['vol']),
                float(value['close'])
            ))

read_write_CSV("600928SH.csv", "600928SH.new.csv")

'''
import pandas as pd
from matplotlib import pyplot as plt
df=pd.read_csv('600028SH.new.csv',parse_dates=['Date Time'],index_col=['Date Time'],sep=',')
print(df.head())
print(df.tail())
print(df.describe())
print("closing price for mosy recent 5 trading days:")
print(df[['Close']].tail())
vol=df[['Volume']]
print("Min:%s Max:%s Average:%s"%(vol.min().values[0],vol.max().values[0],vol.mean().values[0]))
plots=df[['Close','Volume']].plot(subplots=True,figsize=(10,10))
df['ma50']=df['Close'].rolling(50).mean()
df['ma200']=df['Close'].rolling(200).mean()
plots=df[['Close','ma50','ma200']].plot(subplots=False,figsize=(10,4))
plt.show()
'''

